package com.walker.workqueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;
import com.walker.BaseConfig;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Description:
 * @ProjectName: walker-step
 * @Package: com.walker.workqueue
 * @ClassName: WorkQueueSender
 * @Author: yangyl
 * @CreateDate: 2020/6/20 20:55
 */
public class WorkQueueSender {


    public static ConnectionFactory connectionFactory() {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost(BaseConfig.HOST);
        connectionFactory.setVirtualHost(BaseConfig.VHOST);
        connectionFactory.setPort(5672);
        connectionFactory.setUsername(BaseConfig.USERNAME);
        connectionFactory.setPassword(BaseConfig.PASSWORD);
        return connectionFactory;
    }


    public static void main(String[] args) throws Exception {
        ConnectionFactory connectionFactory=connectionFactory();
        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("hello",true,false,false,null);
        for (int i = 0; i < 10; i++) {
            String body="Hello 世界你好"+i;
            for (int j = 0; j < i ; j++) {
                body+=".";
            }
            byte[] bodys=(body).getBytes();
            channel.basicPublish("","hello", MessageProperties.PERSISTENT_TEXT_PLAIN,bodys);
        }

        connection.close();
    }
}
